
layui.use(["form","jquery"],function (form,$){

    form.on("submit(role-mapping-form)",e=>{
        let names = Object.keys(e.field);
        let roleIds = e.field.roleIds = []
        names = names.filter(name=>name.startsWith("roleId"))
        for ( let name of names) {
            roleIds.push(parseInt(e.field[name]))
            delete e.field[name]
        }

        $.ajax({
            type:'post',
            url:`${rootPath}/role/${e.field.id}`,
            dataType:'json',
            data:e.field,
            success(rs) {
                if(rs.code==0) {
                    // 在父页面弹窗提示窗口
                    parent.layer.msg(`关联角色成功`,{icon:6})
                    //重载父页面表格中的数据
                    parent.layui.table.reload('LAY-TABLE',{},true)
                    // 关闭当前弹出框
                    let index = parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index)
                } else  {
                    layer.msg(`关联角色失败`,{icon:5})
                }
            },error(e) {
                layer.msg(`关联角色失败`,{icon:5})
            }

        })
        return false;
    })
})